package com.zmn.oms.services.impl.conf.replay;

import com.zmn.common.dto.StatusDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.model.entity.conf.reply.ReplyContent;
import com.zmn.oms.model.entity.conf.reply.ReplyContentQuery;
import com.zmn.oms.persistence.interfaces.conf.reply.ReplyContentDao;
import com.zmn.oms.services.interfaces.conf.reply.ReplyContentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类描述:回访内容service实现类
 *
 * @author linfeng
 * @since 2019/10/24/9:45
 */
@Service
public class ReplyContentServiceImpl implements ReplyContentService {

    @Resource
    ReplyContentDao replyContentDao;

    @Override
    public Integer countByQuery(ReplyContentQuery query) {
        return replyContentDao.countByQuery(query);
    }

    @Override
    public ReplyContent findByKey(Integer id) {
        return replyContentDao.findByKey(id);
    }

    @Override
    public List<ReplyContent> listPageByQuery(ReplyContentQuery query) {
        int count = replyContentDao.countByQuery(query);
        query.setTotalCount(count);
        return replyContentDao.listPageByQuery(query);
    }

    @Override
    public List<ReplyContent> listByQuery(ReplyContentQuery query) {
        return replyContentDao.listByQuery(query);
    }

    @Override
    public int updateStatusBatch(List<Integer> arrayIds, int status, String updater) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(arrayIds);
        dto.setStatus(status);
        dto.setUpdater(updater);
        dto.setUpdateTime(DateUtil.getNow());
        return replyContentDao.updateStatusBatch(dto);
    }

    @Override
    public Integer updateSortKey(int id, int sort, String updater) {
        ReplyContent returnVisitContent = new ReplyContent();
        returnVisitContent.setId(id);
        returnVisitContent.setSort(sort);
        returnVisitContent.setUpdater(updater);
        returnVisitContent.setUpdateTime(DateUtil.getNow());
        return replyContentDao.updateSortKey(returnVisitContent);
    }

    @Override
    public Integer updateFirstLetterByKey(int id, String firstLetter, String updater) {
        ReplyContent replyContent = new ReplyContent();
        replyContent.setId(id);
        replyContent.setFirstLetter(firstLetter);
        replyContent.setUpdater(updater);
        replyContent.setUpdateTime(DateUtil.getNow());
        return replyContentDao.updateFirstLetterByKey(replyContent);
    }

    @Override
    public Integer insert(ReplyContent replyContent) {
        return replyContentDao.insert(replyContent);
    }

    @Override
    public Integer updateByKey(ReplyContent replyContent) {
        return replyContentDao.updateByKey(replyContent);
    }
}
